package com.zjitc.order;

import java.util.concurrent.Executors;

/**
 * Create by IntelliJ IDEA
 *
 * @author: jsonor
 * @date-Time: 2018/4/18 14:10
 * @description:
 */
public class QueueOrderInfoThread {

  /**
   * 开启线程消费队列中的数据，并将其存入到数据库
   */
  public void start() throws InterruptedException {

    Executors.newSingleThreadExecutor().submit(() -> {
      while (true) {
        try {
          OrderInfo info = QueueOrderInfo.Instance.take();
          if (info.getBuyCount() < 0) {
            // update redis
          }
          System.out.println("收到用户的订单" + info.toString());
          System.out.println("update product set product_count = product_count - 1");
          Thread.sleep(200);
          System.out.println("修改成功");
        } catch (InterruptedException e) {
          e.printStackTrace();
        }
      }
    });

  }
}
